﻿using System;
using ExFlash.Records;

namespace ExFlash.Actions
{
    public class ActionDefineFunction : ActionRecord
    {
        private readonly int _swfVersion;

        public StringRecord FunctionName
        {
            get;
            protected set;
        }

        public ushort NumParams
        {
            get;
            protected set;
        }

        public StringRecord[] Params
        {
            get;
            protected set;
        }

        public ushort CodeSize
        {
            get;
            protected set;
        }

        public ActionDefineFunction(ushort len, int version)
            : base((byte)ActionCodes.ActionDefineFunction, len)
        {
            _swfVersion = version;
        }

        public override void SwfDeserialize(BinaryBitReader reader)
        {
            FunctionName = new StringRecord(_swfVersion);
            FunctionName.SwfDeserialize(reader);

            NumParams = reader.ReadUInt16();

            Params = new StringRecord[NumParams];

            for (int i = 0; i < NumParams; i++)
            {
                Params[i] = new StringRecord(_swfVersion);
                Params[i].SwfDeserialize(reader);
            }

            CodeSize = reader.ReadUInt16();
        }

        public override void SwfSerialize(byte[] arr, ref int offset)
        {
            throw new NotImplementedException();
        }
    }
}
